/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

using System;

using BigEndianSignedByte = argot.common.BigEndianSignedByte;
using BigEndianSignedInteger = argot.common.BigEndianSignedInteger;
using BigEndianSignedLong = argot.common.BigEndianSignedLong;
using BigEndianSignedShort = argot.common.BigEndianSignedShort;
using BigEndianUnsignedByte = argot.common.BigEndianUnsignedByte;
using BigEndianUnsignedInteger = argot.common.BigEndianUnsignedInteger;
using BigEndianUnsignedLong = argot.common.BigEndianUnsignedLong;
using BigEndianUnsignedShort = argot.common.BigEndianUnsignedShort;
using DateS64 = argot.common.DateS64;
using Empty = argot.common.Empty;
using U16ArrayByte = argot.common.U16ArrayByte;
using U32ArrayByte = argot.common.U32ArrayByte;
using U32UTF8 = argot.common.U32UTF8;
using U8Ascii = argot.common.U8Ascii;
using U8Boolean = argot.common.U8Boolean;
using MetaIdentified = argot.meta.MetaIdentified;
using MetaMarshaller = argot.meta.MetaMarshaller;

namespace argot
{
	
	public class TypeBindCommon
	{
		public static void BindCommon(TypeLibrary library)
		{
			if (library.GetTypeState(Empty.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				Empty te = new Empty();
				library.Bind(Empty.TYPENAME, te, te, te.GetType());
			}
			
			// Register Big Endian Unsigned Types.
			if (library.GetTypeState(BigEndianUnsignedByte.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				BigEndianUnsignedByte bbe = new BigEndianUnsignedByte();
				library.Bind(BigEndianUnsignedByte.TYPENAME, bbe, bbe, null);
			}
			
			if (library.GetTypeState(BigEndianUnsignedShort.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				BigEndianUnsignedShort bbs = new BigEndianUnsignedShort();
				library.Bind(BigEndianUnsignedShort.TYPENAME, bbs, bbs, null);
			}
			
			if (library.GetTypeState(BigEndianUnsignedInteger.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				BigEndianUnsignedInteger bei = new BigEndianUnsignedInteger();
				library.Bind(BigEndianUnsignedInteger.TYPENAME, bei, bei, null);
			}
			
			if (library.GetTypeState(BigEndianUnsignedLong.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				BigEndianUnsignedLong bbe = new BigEndianUnsignedLong();
				library.Bind(BigEndianUnsignedLong.TYPENAME, bbe, bbe, null);
			}
			
			// Register Big Endian Signed Types.
			if (library.GetTypeState(BigEndianSignedByte.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				BigEndianSignedByte bbe = new BigEndianSignedByte();
				library.Bind(BigEndianSignedByte.TYPENAME, bbe, bbe, typeof(System.SByte));
			}
			
			if (library.GetTypeState(BigEndianSignedShort.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				BigEndianSignedShort bbs = new BigEndianSignedShort();
				library.Bind(BigEndianSignedShort.TYPENAME, bbs, bbs, typeof(System.Int16));
			}
			
			if (library.GetTypeState(BigEndianSignedInteger.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				BigEndianSignedInteger bei = new BigEndianSignedInteger();
				library.Bind(BigEndianSignedInteger.TYPENAME, bei, bei, typeof(System.Int32));
			}
			
			if (library.GetTypeState(BigEndianSignedLong.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				BigEndianSignedLong bbe = new BigEndianSignedLong();
				library.Bind(BigEndianSignedLong.TYPENAME, bbe, bbe, typeof(System.Int64));
			}
			
			if (library.GetTypeState(U8Ascii.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				U8Ascii sbu = new U8Ascii();
				library.Bind(U8Ascii.TYPENAME, sbu, sbu, typeof(System.String));
			}
			
			if (library.GetTypeState(U32UTF8.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				U32UTF8 sbu = new U32UTF8();
				library.Bind(U32UTF8.TYPENAME, sbu, sbu, null);
			}
			
			if (library.GetTypeState(U16ArrayByte.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				U16ArrayByte aib = new U16ArrayByte();
				library.Bind(U16ArrayByte.TYPENAME, aib, aib, typeof(sbyte[]));
			}
			
			if (library.GetTypeState(U32ArrayByte.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				U32ArrayByte asb = new U32ArrayByte();
				library.Bind(U32ArrayByte.TYPENAME, asb, asb, null);
			}
			
			if (library.GetTypeState(U8Boolean.TYPENAME) == TypeLibrary.TYPE_REGISTERED)
			{
				U8Boolean bb = new U8Boolean();
				library.Bind(U8Boolean.TYPENAME, bb, bb, typeof(System.Boolean));
			}
			
			if (library.GetTypeState("meta.identified") == TypeLibrary.TYPE_REGISTERED)
			{
				MetaIdentified mi = new MetaIdentified("");
				library.Bind(MetaIdentified.TYPENAME, mi, mi, typeof(MetaIdentified));
			}
			
			if (library.GetTypeState("date") == TypeLibrary.TYPE_REGISTERED)
			{
				library.Bind("date", new MetaMarshaller(), new MetaMarshaller(), null);
			}

			if (library.GetTypeState("date.java") == TypeLibrary.TYPE_REGISTERED)
			{
				library.Bind(DateS64.TYPENAME, new TypeReaderAuto(typeof(System.DateTime)), new DateS64(), typeof(System.DateTime));
			}

		}
	}
}